package com.yunang.officialweb.controller;

import com.yunang.officialweb.common.R;
import com.yunang.officialweb.entity.AboutUs;
import com.yunang.officialweb.entity.TotalDesc;
import com.yunang.officialweb.service.AUService;
import com.yunang.officialweb.service.DepService;
import com.yunang.officialweb.service.TotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author duan
 * @date 2022/12/1 13:38
 */
@RestController
@RequestMapping("/OfficialWebsite")
public class AUController {
    @Autowired
    private AUService auService;

    @Autowired
    private TotalService totalService;


    @RequestMapping(value = "/getViewDescOfAU", method = RequestMethod.GET)
    public R getViewDesc(){
        return R.ok(auService.selectViewDesc());
    }

    @RequestMapping(value = "/updateViewDescofAU", method = RequestMethod.PUT)
    public R updateViewDesc(@RequestParam String chineseName,
                                   @RequestParam String text){
        TotalDesc totalDesc = new TotalDesc();
        totalDesc.setChineseName(chineseName);
        totalDesc.setText(text);
        return R.ok(auService.updateViewDesc(totalDesc));
    }

    @RequestMapping(value = "/updateAUComInt", method = RequestMethod.PUT)
    public R updateAUComInt(@RequestParam int  id,
                            @RequestParam(required = false) MultipartFile file,
                            @RequestParam(required = false) String title,
                            @RequestParam(required = false) String Desc){
        AboutUs aboutUs = new AboutUs();
        aboutUs.setId(id);
        aboutUs.setImage(totalService.savePic(file, "D://YunAng-web//aboutUs//"));
        aboutUs.setTitle(title);
        aboutUs.setDesc(Desc);
        return R.ok(auService.updateAU(aboutUs));
    }
}
